package niuke;

import java.util.*;
/**
public class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;

    }

}
*/
public class Solution6 {
     ArrayList<ArrayList<Integer>> ret = new ArrayList<>();
    LinkedList<Integer> tmp = new LinkedList<>();
    public ArrayList<ArrayList<Integer>> FindPath(TreeNode root,int expectNumber) {
        dfs( root, expectNumber);
        return ret;
    }
   
    public void dfs(TreeNode root,int expectNumber){
        if( root == null) return ;
        tmp.add(root.val);
        expectNumber -= root.val;
        if(  expectNumber==0 && root.left == null && root.right == null){
            ret.add(new ArrayList<>(tmp));
        }
        dfs( root.left, expectNumber);
        dfs( root.right, expectNumber);
        tmp.removeLast();
    }
}